package dev.ece.suit.ui.shader;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Map;

import org.lwjgl.opengl.GL20;

import dev.ece.core.shader.DefaultTextureShader;

public class AlphaTextureShader extends DefaultTextureShader {

	private static AlphaTextureShader defaultAlphaTextureShader;
	
	public static AlphaTextureShader getDefaultAlphaTextureShader() throws FileNotFoundException {
		if(defaultAlphaTextureShader == null) {
			defaultAlphaTextureShader = new AlphaTextureShader(
					AlphaTextureShader.class.getClassLoader().getResourceAsStream("shaders/ui/default.vert"), 
					AlphaTextureShader.class.getClassLoader().getResourceAsStream("shaders/ui/alpha.frag")
					);
		}
		return defaultAlphaTextureShader;
	}
	
	private int alphaHandler;
	
	public AlphaTextureShader(InputStream vertexShaderInputStream, InputStream pixelShaderInputStream,
			Map<String, String> functions) {
		super(vertexShaderInputStream, pixelShaderInputStream, functions);
	}

	public AlphaTextureShader(InputStream vertexShaderInputStream, InputStream pixelShaderInputStream) {
		super(vertexShaderInputStream, pixelShaderInputStream);
	}

	public AlphaTextureShader(StringBuffer vertexShaderSource, StringBuffer pixelShaderSource,
			Map<String, String> functions) {
		super(vertexShaderSource, pixelShaderSource, functions);
	}

	public AlphaTextureShader(String vertexShaderSource, String pixelShaderSource) {
		super(vertexShaderSource, pixelShaderSource);
	}

	@Override
	protected void onInitializeHandler(int program) {
		super.onInitializeHandler(program);
		alphaHandler = glGetUniformLocation("alpha");
	}

	public void glAlpha(float alpha) {
		GL20.glUniform1f(alphaHandler, alpha);
	}
	
	@Override
	public void clearup() {
		GL20.glDeleteShader(alphaHandler);
		super.clearup();
	}
	
}
